package com.ffcs.crmd.tsp.task.job.impl.test;

import java.util.concurrent.atomic.AtomicLong;

import com.ffcs.crmd.tsp.api.dto.task.TspJobExecutionException;
import com.ffcs.crmd.tsp.api.task.job.IJob;
import com.ffcs.crmd.tsp.api.task.job.IJobExecutionContext;

public class SimpleJobRandomImpl implements IJob<String> {
    
    private static AtomicLong index = new AtomicLong();
    
    @Override
    public void execute(IJobExecutionContext<String> context) throws TspJobExecutionException {
        long random = (long) (Math.random() * 10000);
        System.out.println(context.getTspJobInstance().getJobKey() + " --- count" + index.incrementAndGet() + " ---waiting time:" + random);
        try {
            Thread.sleep(random);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    
}
